﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using WebMvc.Areas.Sys.Controllers;
using WebMvc.Areas.Sys.Models;

namespace WebMvc.Components
{
    [ViewComponent(Name = "Menu")]
    public class MenuViewComponent : ViewComponent
    {
        public IViewComponentResult Invoke()
        {
            var userId = User.Identity.Name;  //获取登录时存储的用户名称(此处是user.id）

            MenuController _ms = new MenuController();           
            if (userId == null)
            {
                //ViewBag.currentUserName = "";
                return View(new List<Menu>());  //返回一个空的
            }            
            var menus = _ms.GetMenusByUserId(int.Parse(userId));
            
            return View(menus);
        }
    }
}
